// ==========================================================================
// gin-sns自动生成业务逻辑层相关代码，只生成一次，按需修改,再次生成不会覆盖.
// 生成日期：2020-02-18 15:44:13
// 生成路径: app/service/module/log/log_service.go
// 生成人：jon
// ==========================================================================
package monitor

import (
	"errors"
	"gin-sns/app/ginframe/utils/convert"
	"gin-sns/app/ginframe/utils/page"

	"gin-sns/app/dao/monitor/job_log"
	jobLogModel "gin-sns/app/model/monitor/job_log"
)

var JobLogService = newJobLogService()

func newJobLogService() *jobLogService {
	return &jobLogService{}
}

type jobLogService struct {
}

//根据主键查询数据
func (s *jobLogService) SelectRecordById(id int64) (*jobLogModel.Entity, error) {
	entity := &jobLogModel.Entity{JobLogId: id}
	have, err := job_log.JobLogDao.FindOne(entity)
	if !have {
		err = errors.New("not found")
		entity = nil
	}
	return entity, err
}

//根据主键删除数据
func (s *jobLogService) DeleteRecordById(id int64) bool {
	entity := &jobLogModel.Entity{JobLogId: id}
	result, err := job_log.JobLogDao.Delete(entity)
	if err == nil && result > 0 {
		return true
	}

	return false
}

//批量删除数据记录
func (s *jobLogService) DeleteRecordByIds(ids string) int64 {
	idarr := convert.ToInt64Array(ids, ",")
	result, _ := job_log.JobLogDao.DeleteBatch(idarr...)
	return result
}

//根据条件查询数据
func (s *jobLogService) SelectListAll(params *jobLogModel.SelectPageReq) ([]jobLogModel.Entity, error) {
	return job_log.JobLogDao.SelectListAll(params)
}

//根据条件分页查询数据
func (s *jobLogService) SelectListByPage(params *jobLogModel.SelectPageReq) (*[]jobLogModel.Entity, *page.Paging, error) {
	return job_log.JobLogDao.SelectListByPage(params)
}

// 导出excel
func (s *jobLogService) Export(param *jobLogModel.SelectPageReq) (string, error) {
	head := []string{"任务日志ID", "任务名称", "任务组名", "调用目标字符串", "日志信息", "执行状态（0正常 1失败）", "异常信息", "创建时间"}
	col := []string{"job_log_id", "job_name", "job_group", "invoke_target", "job_message", "status", "exception_info", "create_time"}
	return job_log.JobLogDao.SelectListExport(param, head, col)
}
